package com.online.teaching.dao;
import com.online.teaching.pojo.File;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/****
 * @Author:admin
 * @Description:File的Dao
 * @Date 2019/6/14 0:12
 *****/
public interface FileMapper extends Mapper<File>, IdListMapper<File,Integer> {
    /**
     * 查询字目录，递归删除
     * @param parentIdList
     * @return
     */
    @Select({"<script>select * from file where parent_id in "
            + "<foreach item='item' index='index' collection='parentIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>"})
    List<File>selectChildren(List<Integer> parentIdList);

    /**
     * 根据所在课程查询目录树
     * @param teachesId
     * @return
     */
    @Select("SELECT * FROM file WHERE teaches_id =#{teaches_id} AND type =1")
    List<File>selectFileByTeachesId(@ApiParam("teaches_id") Integer teachesId);


    /**
     * 查询这个parentid下的全部文件
     * @param parentId
     * @return
     */
    @Select("SELECT * FROM file WHERE parent_id=#{parent_id} AND type = 0")
    List<File>selectFileListByParent(@ApiParam("parent_id") Integer parentId);
}
